﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using EntityFrameworkContrib.PostSharp4EF;

namespace Server
{
    public static class ContextExtensions
    {
        public static void PrepareForSerialization(this ObjectContext context, object graphRoot)
        {
            ((IContextAware) graphRoot).CreateSerializableState(context);
        }

        public static void AttachToContext(this ObjectContext context, object graphRoot, Func<object, string> GetEntitySet)
        {
            ((IContextAware) graphRoot).AttachGraphToContext(context, GetEntitySet);
        }

        public static void AttachToContext(this InheritanceTypeContext context, object graphRoot)
        {
            ((IContextAware) graphRoot).AttachGraphToContext(context,
                delegate(object instance)
                {
                    // we're in luck, we have only 1 entityset
                    return "Person";
                }
                );
        }
    }
}
